import {_decorator, Component, Node} from 'cc';
import {AccountModule} from "db://assets/scripts/modules/login/core/AccountModule";
import {RoleInfoPrefUI} from "db://assets/scripts/modules/login/ui/RoleInfoPrefUI";
import {RoleInfo} from "db://assets/scripts/obj/RoleInfo";
import {FloatingTextManager} from "db://assets/scripts/common/FloatingTextManager";
import {NetManager} from "db://assets/scripts/common/NetManager";
import {PrefabManager} from "db://assets/scripts/common/PrefabManager";
import {PrefabDefs} from "db://assets/scripts/defs/PrefabDefs";

const {ccclass, property} = _decorator;

@ccclass('LoginScene')
export class LoginScene extends Component {

    @property(Node)
    private loginPanel: Node = null;

    @property(Node)
    private roleList :Node = null;

    start() {
        // 加载预制体
        PrefabManager.getInstance().init();
        // 初始化socket连接
        NetManager.getInstance().init();
        // 各个模块初始化
        AccountModule.getInstance().init(this);
    }

    // 账号登录成功
    onAccountLoginSuccess(roleInfos: RoleInfo[]) {
        FloatingTextManager.showText("账号登陆成功");
        this.roleList.removeAllChildren();
        // 关闭登录界面，打开选角界面
        this.loginPanel.active = false;
        this.roleList.active = true;
        // 根据角色列表创建子类
        for (let i = 0; i < 3; i++) {
            let roleInfo = roleInfos.pop();
            let node: Node = PrefabManager.instantiate(PrefabDefs.RoleInfoPref);
            node.getComponent(RoleInfoPrefUI).roleInfo = roleInfo;
            this.roleList.addChild(node);
        }

    }


}


